<template>
  <div class="dashboard-editor-container">
    <el-row :gutter="10" class="panel-group">
      <el-col :span="24" class="time-card">
        <!-- <el-card> -->
        <el-form :model="queryParams" :inline="true">
          <el-form-item prop="supermarketId">
            <el-select
              v-model="queryParams.supermarketId"
              clearable
              placeholder="全部来源数据"
            >
              <el-option
                v-for="item in supermarketOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
              >
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-date-picker
              v-model="dateRange"
              :editable="true"
              value-format="yyyy-MM-dd"
              type="daterange"
              :picker-options="pickerOptions"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              align="right"
              :clearable="false"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button @click="getList">搜索</el-button>
          </el-form-item>
        </el-form>
        <!-- </el-card> -->
      </el-col>
      <el-col :span="12" class="card-panel-col">
        <div class="card-panel">
          <h3>销售金额（单位：元）</h3>

          <div class="card-panel-icon-wrapper icon-money">
            <svg-icon icon-class="money" class-name="card-panel-icon" />
          </div>
          <div class="card-panel-description">
            <count-to
              :start-val="0"
              :end-val="total.amountTotal[1]"
              :duration="100"
              class="card-panel-num"
            />
            <div class="card-panel-text">销售总额</div>
          </div>

          <div>
            <div class="card-panel-icon-wrapper icon-money">
              <svg-icon icon-class="money" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <count-to
                :start-val="0"
                :end-val="total.amountTotal[0]"
                :duration="100"
                class="card-panel-num"
              />
              <div class="card-panel-text">未支付总额</div>
            </div>

            <div>
              <div class="card-panel-icon-wrapper icon-money">
                <svg-icon icon-class="money" class-name="card-panel-icon" />
              </div>
              <div class="card-panel-description">
                <count-to
                  :start-val="0"
                  :end-val="total.numberTotal[3]"
                  :duration="10"
                  class="card-panel-num"
                />
                <div class="card-panel-text">订单总数</div>
              </div>
            </div>
          </div>
        </div>
      </el-col>
      <el-col :span="12" class="card-panel-col">
        <div class="card-panel">
          <h3>人员统计</h3>

          <div class="peopleTotal">
            <div class="card-panel-icon-wrapper icon-people">
              <svg-icon icon-class="people" class-name="card-panel-icon" />
            </div>
            <div class="card-panel-description">
              <count-to
                :start-val="0"
                :end-val="total.numberTotal[0]"
                :duration="10"
                class="card-panel-num"
              />
              <div class="card-panel-text">员工人数</div>
            </div>
            <div class="peopleTotal">
              <div class="card-panel-icon-wrapper icon-people">
                <svg-icon icon-class="people" class-name="card-panel-icon" />
              </div>
              <div class="card-panel-description">
                <count-to
                  :start-val="0"
                  :end-val="total.numberTotal[1]"
                  :duration="10"
                  class="card-panel-num"
                />
                <div class="card-panel-text">休假人数</div>
              </div>
              <div>
                <div class="card-panel-icon-wrapper icon-people">
                  <svg-icon icon-class="people" class-name="card-panel-icon" />
                </div>
                <div class="card-panel-description">
                  <count-to
                    :start-val="0"
                    :end-val="total.numberTotal[2]"
                    :duration="10"
                    class="card-panel-num"
                  />
                  <div class="card-panel-text">会员人数</div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </el-col>
    </el-row>
    <el-row
      :gutter="10"
      style="background: #fff; padding: 16px 16px 0; margin-bottom: 1px"
    >
      <el-col :span="24">
        <line-chart :chart-data="lineChartData" />
      </el-col>
      <!-- <el-col :span="8">
        <div class="chart-wrapper">
          <raddar-chart />
        </div>
      </el-col> -->
    </el-row>
    <!-- <raddar-chart></raddar-chart>
    <pie-chart />
    <bar-chart></bar-chart> -->
  </div>
</template>

<script>

import LineChart from "./dashboard/LineChart";
import RaddarChart from "./dashboard/RaddarChart";
import PieChart from "./dashboard/PieChart";
import BarChart from "./dashboard/BarChart";

import CountTo from "vue-count-to";
import { getSupermarketName } from "@/api/supermarket/supermarket";
import { indextotal } from "@/api/supermarket/indexTotal";

const lineChartData = {
  newVisitis: {
    expectedData: [100, 120, 161, 134, 105, 160, 165],
    actualData: [120, 82, 91, 154, 162, 140, 145],
  },
  messages: {
    expectedData: [200, 192, 120, 144, 160, 130, 140],
    actualData: [180, 160, 151, 106, 145, 150, 130],
  },
  purchases: {
    expectedData: [80, 100, 121, 104, 105, 90, 100],
    actualData: [120, 90, 100, 138, 142, 130, 130],
  },
  shoppings: {
    expectedData: [130, 140, 141, 142, 145, 150, 160],
    actualData: [120, 82, 91, 154, 162, 140, 130],
  },
};

export default {
  name: "Index",
  components: {
    LineChart,
    RaddarChart,
    PieChart,
    BarChart,
    CountTo,
  },
  data() {
    return {
      //超市选项
      supermarketOptions: [],
       dateRange: [],
      // total 统计数据对象
      total:'',

      
      //查询参数
      queryParams: {
        supermarketId: undefined,
      },
      lineChartData: '',

      pickerOptions: {
        shortcuts: [
          {
            text: "最近7天",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              console.log(start);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近30天",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近60天",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 60);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },

  created() {
    this.getSupermarketNameList();
    this.getList();
  },

  methods: {
    getList() {
      indextotal(this.addDateRange(this.queryParams, this.dateRange)).then((response) => {
        this.total = response.data;
         this.lineChartData = this.total.lineAmountTotal;   
        console.log(this.total);
        console.log(this.lineTotal)

      });
    },

    // 初始化超市名称
    getSupermarketNameList() {
      if (this.$store.getters.userId == 0) {
        return;
      }
      const userId = this.$store.getters.userId;
      getSupermarketName(userId).then((response) => {
        this.supermarketOptions = response.data;
      });
    },
  },
};
</script>

<style lang="scss" scoped>

.dashboard-editor-container {
  padding: 1px 20px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-bottom: 1px;
  }
}
.time-card {
  position: relative;
  overflow: hidden;
  color: #666;
  margin-top: 0;
  background: #fff;
  box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
  border-color: rgba(0, 0, 0, 0.05);
}

.time-card form{

  margin-top: 10px;
}
el-select {
  width: 30px;
}
h3 {
  margin-left: 15px;
  font-weight: bold;
}
.panel-group {
  margin-top: 3px;
  border: 1px solid rgb(240, 242, 245);
  .card-panel-col {
    margin-bottom: 10px;
  }

  .card-panel {
    height: 150px;
    cursor: pointer;
    font-size: 12px;
    position: relative;
    overflow: hidden;
    color: #666;
    background: #fff;
    box-shadow: 4px 4px 40px rgba(0, 0, 0, 0.05);
    border-color: rgba(0, 0, 0, 0.05);

    &:hover {
      .card-panel-icon-wrapper {
        color: #fff;
      }

      .icon-people {
        background: #40c9c6;
      }

      .icon-message {
        background: #36a3f7;
      }

      .icon-money {
        background: #f4516c;
      }

      .icon-shopping {
        background: #34bfa3;
      }
    }

    .icon-people {
      color: #40c9c6;
    }

    .icon-message {
      color: #36a3f7;
    }

    .icon-money {
      color: #f4516c;
    }

    .icon-shopping {
      color: #34bfa3;
    }

    .card-panel-icon-wrapper {
      float: left;
      margin: 10px 20px 0 20px;
      padding: 5px;
      transition: all 0.38s ease-out;
      border-radius: 6px;
      position: relative;
      left: 80px;
    }

    .card-panel-icon {
      float: none;
      font-size: 20px;
    }

    .card-panel-description {
      float: left;
      font-weight: bold;
      margin: 40px;
      margin-left: 15px;

      .card-panel-text {
        line-height: 20px;
        color: rgba(0, 0, 0, 0.45);
        font-size: 16px;
        margin-top: 10px;
      }

      .card-panel-num {
        font-size: 20px;
        margin-left: 15px;
      }
    }
  }
}

@media (max-width: 500px) {
  .card-panel-description {
    display: none;
  }

  .card-panel-icon-wrapper {
    float: none !important;
    width: 100%;
    height: 100%;
    margin: 0 !important;

    .svg-icon {
      display: block;
      margin: 14px auto !important;
      float: none !important;
    }
  }
}

@media (max-width: 1024px) {
  .chart-wrapper {
    padding: 8px;
  }
}
</style>
